<?php

function shusy_stats_page() {
  $query = db_select('shusy_stats', 's');
  $query->fields('s', ['id', 'type', 'number']);
  $inday = strtotime(format_date(REQUEST_TIME, 'custom', 'Y-m-d'));
  $query->condition('inday', $inday);
  $result = $query->execute();
  $orders = 0;
  $amounts = 0;
  $uids = 0;
  $pays = 0;
  $views = 0;
  while ($row = $result->fetchAssoc()) {
    switch ($row['type']) {
      case 'orders':
        $orders = $row['number'];
        break;
      case 'amounts':
        $amounts = bcdiv($row['number'], 100, 2) + 0;
        break;
      case 'uids':
        $uids = $row['number'];
        break;
      case 'pays':
        $pays = $row['number'];
        break;
      case 'views':
        $views = $row['number'];
        break;
    }
  }
  $stats = [
    'orders' => $orders,
    'amounts' => $amounts,
    'uids' => $uids,
    'pays' => $pays,
    'views' => $views,
    'date' => format_date($inday, 'custom', 'Y-m-d'),
  ];
  return theme('shusy_stats', [
    'stats' => $stats,
  ]);
}
